package com.pansoft.newasset.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.efounder.chat.model.AppConstant;
import com.efounder.chat.utils.LXGlideImageLoader;
import com.pansoft.newasset.bean.MenuBean;
import com.pansoft.openplanet.R;

import java.util.List;

public class NewAssetMenuAdapter extends BaseAdapter {

    private List<MenuBean> items;
    private Context context;

    public NewAssetMenuAdapter(Context context, List<MenuBean> items) {
        this.context = context;
        this.items = items;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;

        if (convertView == null) {
            // if it's not recycled, initialize some attributes
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.new_asset_item_menu,
                    parent, false);
            viewHolder.ivIcon = convertView.findViewById(R.id.img);
            viewHolder.tvKindName = convertView.findViewById(R.id.text);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        String filepath = AppConstant.APP_ROOT + "/res/unzip_res/menuImage/" + items.get(position).getIcon();
        LXGlideImageLoader.getInstance().displayImage(context, viewHolder.ivIcon,
                "file://" + filepath);
        viewHolder.tvKindName.setText(items.get(position).getName());
        return convertView;
    }
    public class ViewHolder{
        ImageView ivIcon;
        TextView tvKindName;
    }
}
